﻿@model ListConfig
@using MvcTestApp.Models;

@{
    ListConfig _Config = Model as ListConfig;    
    System.Data.DataTable dt = _Config.DataSource;
}
<table cellpadding="3" cellspacing="0" style="width:100%;">
    <tr>
        @foreach (Group group in _Config.Groups)
        {
            <th>@group.Name</th>
        }
        @if (_Config.ShowEditLink)
        {
            <th style="text-align:center;">Action</th>
        }
    </tr>
    @foreach (System.Data.DataRow row in dt.Rows)
    {
        <tr>
            @foreach(Group group in _Config.Groups)
            {
                <td>
                    @foreach (Field field in group.Fields)
                    {
                        if (String.IsNullOrEmpty(field.StringFormat))
                        {
                        <div>
                            <b>@field.Name: </b> @row[field.Name]
                        </div>
                        }
                        else
                        {
                            List<String> values = new List<String>();
                            foreach (String fieldName in field.Params)
                            {
                                ///Need to Convert and Format the Value Strings according to their Type
                                values.Add(row[fieldName].ToString());
                            }
                            <div>
                                @Html.Raw(String.Format(field.StringFormat, values.ToArray()))
                            </div>
                        }
                    }
                </td>
            }
            @if (_Config.ShowEditLink)
            {
                <td style="text-align:center;"><a href="@String.Format(_Config.EditLinkFormat, row["ID"])">Edit</a></td>
            }
        </tr>
    }
</table>